#include <iostream>
#include <pthread.h>
#include<unistd.h>
#include<string>
using namespace std;
class Task{
    public:
    Task(int a,int b):a(a),b(b){}
    int Execute(){
        return a+b;
    }
    private:
    int a;
    int b;
};
class Result{
    public:
    Result(int result):result(result){}
    int getResult(){
        return result;
    }
    private:
    int result;
};
void* thread_func(void* arg){
    pthread_detach(pthread_self());
   Task* task=(Task*)arg;
   task->Execute();
   sleep(1);
   Result* result=new Result(task->Execute());
   sleep(1);
   delete task;
   cout<<"thread exit"<<pthread_self()<<endl;
   pthread_exit((void*)result);

}
int main(){
    pthread_t tid;
    Task *task(new Task(1,2));
    pthread_create(&tid,NULL,thread_func,(void*)task);
    //pthread_cancel(tid);
    // Result *ret=nullptr;
    // pthread_join(tid,(void**)&ret);
    // cout<<"result:"<<ret->getResult()<<endl;
    // delete ret;
    // cout<<"main exit"<<tid<<endl;
    cout<<"main exit"<<endl;
    sleep(10);
    return 0;
}